#pragma once


namespace SD_Tools
{
	class SimpleTray
	{
	private:
	public:
	private:
	public:
		static ATOM CreateRegisterClass(HINSTANCE hInstance, WNDPROC Proc, UINT IconResId, wchar_t* MenuName, wchar_t* ClassName);
		static HWND CreateInvisHwnd(wchar_t* ClassName, wchar_t* WindowName, HINSTANCE hInstance);
		static void InitNotifyIconData(NOTIFYICONDATA* Data, UINT IconResId, HWND hWnd, HINSTANCE hInstance, UINT MessageId, wchar_t* ToolTip = NULL);
		static void CreateShellMenu(NOTIFYICONDATA* Data);
		static void ReleaseShellMenu(NOTIFYICONDATA* Data);
	};


	ATOM SimpleTray::CreateRegisterClass( HINSTANCE hInstance, WNDPROC Proc, UINT IconResId, wchar_t* MenuName, wchar_t* ClassName )
	{
		WNDCLASSEX wcex;
		wcex.cbSize = sizeof(WNDCLASSEX);

		wcex.style			= CS_HREDRAW | CS_VREDRAW;
		wcex.lpfnWndProc	= Proc;
		wcex.cbClsExtra		= 0;
		wcex.cbWndExtra		= 0;
		wcex.hInstance		= hInstance;
		wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IconResId));
		wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
		wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
		wcex.lpszMenuName	= MenuName;
		wcex.lpszClassName	= ClassName;
		wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IconResId));

		return RegisterClassEx(&wcex);
	}

	void SimpleTray::InitNotifyIconData( NOTIFYICONDATA* Data, UINT IconResId, HWND hWnd, HINSTANCE hInstance, UINT MessageId, wchar_t* ToolTip /*= NULL*/ )
	{
		ZeroMemory(Data, sizeof(NOTIFYICONDATA));
		Data->cbSize = NOTIFYICONDATA_V1_SIZE;
		Data->uID = IconResId;
		Data->uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP;
		Data->hIcon = (HICON)LoadImage( hInstance, MAKEINTRESOURCE(IconResId), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
		Data->hWnd = hWnd;
		Data->uCallbackMessage = MessageId;
		if (ToolTip)
		{
			wcscpy(Data->szTip, ToolTip);
		}
	}

	void SimpleTray::CreateShellMenu( NOTIFYICONDATA* Data )
	{
		Shell_NotifyIcon(NIM_ADD, Data);
	}

	void SimpleTray::ReleaseShellMenu( NOTIFYICONDATA* Data )
	{
		Shell_NotifyIcon(NIM_DELETE, Data);
	}

	HWND SimpleTray::CreateInvisHwnd( wchar_t* ClassName, wchar_t* WindowName, HINSTANCE hInstance )
	{
		return CreateWindow(ClassName, WindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
	}

};
















